/**
 * Project: complex.algorithm
 * 
 * File Created at 2011-8-30
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.complex.algorithm;

/**
 * shell
 * @author ymkyve
 *
 */
public class ShellSort extends Sort{
    public static void main(String[] args) {
        ShellSort sort =new ShellSort();
        sort.sort();
        sort.print();
    }

    @Override
    public void sort() {
        int j=0;
        int temp=0;
        
        //分组
        for(int increment=arr.length/2;increment>0;increment/=2){
            
           //每个组内排序
            for(int i=increment;i<arr.length;i++){
                
                temp=arr[i];
                for(j=i;j>=increment;j-=increment){
                    if(temp<arr[j-increment]){
                        arr[j] = arr[j-increment];
                        
                    }else{
                        break;
                    }
                }
                arr[j]=temp;
            }
            
        }
    }

}
